package y23.Dec;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test4 {
    //杨辉三角
    public static void main(String[] args) {
        System.out.println(generate(2));
        System.out.println(generate(3));
        System.out.println(generate(4));
        System.out.println(generate(5));
        System.out.println(getRow(1));
        System.out.println(getRow(2));
        System.out.println(getRow(3));
        System.out.println(getRow(4));
        System.out.println(getRow(5));

    }
    public static List<List<Integer>> generate(int numRows){
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> row = new ArrayList<>();
        row.add(1);
        ret.add(row);
        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            for (int j = 1; j < i; j++) {
                curRow.add(ret.get(i-1).get(j)+ret.get(i-1).get(j-1));
            }
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }

    public static List<Integer> getRow(int rowIndex) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> row = new ArrayList<>();
        row.add(1);
        ret.add(row);
        for (int i = 1; i < rowIndex; i++) {
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            for (int j = 1; j < i; j++) {
                curRow.add(ret.get(i-1).get(j)+ret.get(i-1).get(j-1));
            }
            curRow.add(1);
            ret.add(curRow);

        }
        row = ret.get(rowIndex-1);
        return row;
    }
}
